package com.springboot.config.shiro;

import com.springboot.project.common.service.impl.ModuleServiceImpl;
import com.springboot.project.common.service.impl.UserServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lby.
 * Date: 2018/4/6.
 * Version: V1.0.
 */
@Component
public class ShiroTool {

    @Autowired
    static ModuleServiceImpl ms;

    @Autowired
    static UserServiceImpl us;

    /**
     * 根据roleId获取权限列表
     * @param roleId
     * @return
     */
    public static List<String> getPermissionsByRoleId(int roleId)
    {
        return ms.getPermissionsByRoleId(roleId);
    }

    /**
     * 根据roleId获取roleName
     * @param roleId
     * @return
     */
    public static String getRoleNameById(int roleId) {
        return us.getRoleNameById(roleId);
    }

    public static boolean isLogin()
    {
        if (SecurityUtils.getSubject() != null && SecurityUtils.getSubject().getPrincipal() != null)
        {
            return true;
        }
        return false;
    }
}
